package com.yunhe.common.util;

import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName BeansUtil
 * @Description TODO
 * @Author HeTao
 * @Date 2021/5/12 14:55
 * @Version 1.0
 **/
public final  class BeansUtil {

    private BeansUtil() {
    }

    public static <T1, T2> List<T2> listCopy(List<T1> sourceList, Class<T2> clazz) {
        return (List) sourceList.stream().map((source)->{
            Object target;
            try {
                target = clazz.getDeclaredConstructor().newInstance();
            } catch (Exception e) {
                throw new RuntimeException();
            }
            BeanUtils.copyProperties(source, target);
            return target;
        }).collect(Collectors.toList());
    }
}
